package com.fc.v2.controller;

import com.fc.v2.domain.AjaxResult;
import com.fc.v2.model.auto.SysTenant;
import com.fc.v2.model.custom.Tablepar;
import com.fc.v2.service.auto.ISysTenantService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 租户controller
 * @Classname SysTenantController
 * @Date 2022/1/25 20:08
 * @Created by 87766867@qq.com
 */
@RestController
@RequestMapping("/SysTenantController")
public class SysTenantController {


    private final ISysTenantService iSysTenantService;

    public SysTenantController(ISysTenantService iSysTenantService) {
        this.iSysTenantService = iSysTenantService;
    }

    /****
     * 分页查询
     * @params [tablepar]
     * @returns com.github.pagehelper.PageInfo<com.fc.v2.model.auto.SysTenant>
     * @Date 2022/1/25 20:12
     * @Created by 87766867@qq.com
     */
    @GetMapping("/list")
    public PageInfo<SysTenant> list(Tablepar tablepar){
        PageHelper.startPage(tablepar.getPage(), tablepar.getLimit());
        List<SysTenant> list= iSysTenantService.list();
        return new PageInfo<>(list);
    }



    /***
     * 根据id信息
     * @params [tenantId]
     * @returns com.fc.v2.domain.AjaxResult
     * @Date 2022/1/25 20:12
     * @Created by 87766867@qq.com
     */
    @GetMapping("/getTenantId/{tenantId}")
    public AjaxResult getUserId(@PathVariable("tenantId") String tenantId){
        return AjaxResult.successData(iSysTenantService.getById(tenantId));
    }

    /****
     * 添加
     * @params [SysTenant]
     * @returns com.fc.v2.domain.AjaxResult
     * @Date 2022/1/25 20:11
     * @Created by 87766867@qq.com
     */
    @PostMapping("/add")
    public AjaxResult add(@RequestBody SysTenant SysTenant){
        SysTenant.setCreateTime(LocalDateTime.now());
        return AjaxResult.successData(iSysTenantService.save(SysTenant));
    }
    /***
     * 修改
     * @params [SysTenant]
     * @returns com.fc.v2.domain.AjaxResult
     * @Date 2022/1/25 20:11
     * @Created by 87766867@qq.com
     */
    @PutMapping("/update")
    public AjaxResult update(@RequestBody SysTenant SysTenant){
        SysTenant.setUpdateTime(LocalDateTime.now());
        return AjaxResult.successData(iSysTenantService.updateById(SysTenant));
    }
    /***
     * 删除租户
     * @params [roleId]
     * @returns com.fc.v2.domain.AjaxResult
     * @Date 2022/1/25 20:11
     * @Created by 87766867@qq.com
     */
    @DeleteMapping("/delete/{roleId}")
    public  AjaxResult delete(@PathVariable("roleId") String roleId){
        return AjaxResult.successData(iSysTenantService.removeById(roleId));
    }

}
